<!DOCTYPE html>
<!-- Test page for Chrome OS register form that is hosted at OEM partner site
     and is loaded in chrome://register host page -->
<html><head>
<title>Registration test form</title>
<style>

#main {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  padding: 10px;
  overflow: hidden;
  background: -webkit-gradient(linear, left top, left bottom, from(#FAFBFB), to(#CCD1D4));
}
</style>
<script>
document.addEventListener('DOMContentLoaded', load);
var hostUrl = 'chrome://register';

window.addEventListener('message', processMessage);

function $(o) {
  return document.getElementById(o);
}

function load() {
  var msg = {
    type: 'get_user_info',
    domain: location.href,
    payload: {}
  };
  window.parent.postMessage(msg, hostUrl);
  $('url').textContent = location.href;
}

function processMessage(e) {
  // TODO(nkostylev): e.origin is passed as null and not checked.
  // Probably because it's served from chrome:// scheme.
  if (e.data.domain != hostUrl) {
    registration(false);
    return;
  }
 
  if (e.data.type == 'set_user_info') {
    var info = e.data.payload;
    $('info').textContent = 'OS: ' + info.os_name + ', ' +
        info.os_version + ' SKU:' + info.system_sku + ', system hwqual: ' +
        info.system_hwqual + ', SN: ' + info.system_serial + ', lang: ' +
        info.os_language + ', connection: ' + info.os_connection + ', user: ' +
        info.user_email;
  }

  $('messageInfo').textContent = 'e.origin: ' + e.origin +
      ', e.data.domain: ' + e.data.domain;
}

function registration(result) {
  var msg = {
    type: 'complete_registration',
    domain: location.href,
    payload: {
      registration_status: result
    }
  };
  var parent = window.parent;
  parent.postMessage(msg, hostUrl);
}
</script>
</head>
<body>
<div id="main">
  <h3>Register your computer with Google</h3>
  <i>This registration form is hosted at </i><div id="url"></div><br>
  <i>User info received from host page:</i><br>
  <div id="info"></div><br>
  <i>Message info:</i><br>
  <div id="messageInfo"></div><br>
  <input type="button" value="Skip" onclick="registration(false);">
  <input type="button" value="Register" onclick="registration(true);">
</div>
</body></html>